import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession
import org.apache.spark.{SparkConf, SparkContext}
object FilterRDD {
  def main(args: Array[String]): Unit = {
    try {


      val conf = new SparkConf().setAppName("RDDFilterDemo").setMaster("local[*]")
      val sc = new SparkContext(conf)

      val baseRDD = sc.parallelize(Seq(('a', 1), ('b', 2), ('c', 3)))


      val filteredByPlaceholder = baseRDD.filter(_._2 > 1)


      val filteredByLambda = baseRDD.filter { case (char, num) =>
        num > 1 && char != 'd'
      }

      // 执行动作操作并打印结果
      println("占位符语法结果：" + filteredByPlaceholder.collect().mkString(", "))
      println("Lambda表达式结果：" + filteredByLambda.collect().mkString(", "))
    }
  }

}
